import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/models/response/my_account.dart';
import 'package:sainbainu/common/models/response/user_info.dart';
import 'package:sainbainu/common/values/sizes.dart';

import '../index.dart';

/// hello
class CustomSliverAppBar extends GetView<MyController> {
  final Widget headContent;
  final PreferredSizeWidget? bottom;
  final VoidCallback? onMore;
  final Rx<MyAccountResponse> userInfo;

  const CustomSliverAppBar({
    Key? key,
    required this.headContent,
    required this.userInfo,
    this.bottom,
    this.onMore,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return _buildSliverAppBar();
  }

  /// 头部
  _buildSliverAppBar() {
    return SliverAppBar(
      leading: Obx(
        () => IconButton(
          onPressed: () {},
          icon: Icon(
            Icons.ios_share,
            color: controller.state.isCollapsed.value
                ? Colors.black
                : Colors.white,
          ),
        ),
      ),
      actions: [
        Obx(
          () => IconButton(
            onPressed: () {
              if (onMore != null) {
                onMore!();
              }
            },
            icon: Icon(
              Icons.settings_rounded,
              color: controller.state.isCollapsed.value
                  ? Colors.black
                  : Colors.white,
            ),
          ),
        )
      ],
      title: Obx(
        () => Opacity(
          opacity: controller.state.titleOpacity.value,
          child: Text(userInfo.value.nickName ?? ''),
        ),
      ),
      pinned: true,
      stretch: true,
      expandedHeight: kProfileCoverHeight,
      flexibleSpace: FlexibleSpaceBar(
        collapseMode: CollapseMode.parallax,
        background: headContent,
      ),
      bottom: bottom,
    );
  }
}
